var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollTop: 0,
    introNavObj: {
      active: "0",
      fixed: !1
    },
    showOrgList: !1,
    selectCityIndex: 0,
    nesARR: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var id = options.tid
    that.setData({
      id: id
    })
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.gettijiandetail()
    that.calculate()

  },
  calculate: function () {
    var t = this;
    wx.createSelectorQuery().select("#intro0").boundingClientRect().select("#intro1").boundingClientRect().select("#intro2").boundingClientRect().select("#intro-nav").boundingClientRect().exec(function (o) {

      if (o[3]) {
        var i = o[3].height;
        t.setData({
          "introNavObj.intro0": o[0].top - i,
          "introNavObj.intro1": o[1].top - i,
          "introNavObj.intro2": o[2].top - i,
          "introNavObj.introNav": o[3].top
        });
      }

    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  gettijiandetail() {
    var that = this
    var id = that.data.id
    app.util.request({
      'url': 'entry/wxapp/tijian.detail',
      data: {
        id: id
      },
      success: function (res) {
        console.log(res)
        var hid = res.data.hid
        that.setData({
          detail: res.data,
          is_fenxiao: res.data.is_fenxiao,
          imgpath: res.data.imgpath,
          hid: hid
        })
        that.getcityjigou()
      }
    })
  },
  showTip: function (e) {
    console.log(e)
    var that = this
    var t_msg2 = e.currentTarget.dataset.t_msg2
    wx.showModal({
      title: '提示',
      content: t_msg2,
      showCancel: false,
      confirmText: '我知道了',
      confirmColor: '#fd965b',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },

  goScrollPosition: function (t) {
    var o = t.currentTarget.dataset.index;
    console.log(o)
    this.setData({
      "introNavObj.active": o,
    })
    wx.pageScrollTo({
      scrollTop: this.data.introNavObj["intro" + o] + 1
    });
  },
  onPageScroll: function (t) {
    this.goScroll(t);
  },
  goScroll: function (t) {
    var o = t.scrollTop,
      i = this.data.introNavObj,
      n = (i.intro0, i.intro1),
      e = i.intro2,
      r = i.introNav,
      a = "0";
    o >= e ? a = "2" : o >= n && o < e ? a = "1" : o < n && (a = "0"), this.data.showOrgList || this.setData({
      // "introNavObj.active": a,
      "introNavObj.fixed": o >= r,
      scrollTop: o
    });
  },
  showOrgList(s) {
    var that = this
    var index = s.currentTarget.dataset.index ? s.currentTarget.dataset.index : that.data.index
    that.setData({
      showOrgList: !0
    })

  },
  getcityjigou() {
    var that = this
    var id = that.data.id
    var hid = that.data.hid
    console.log(hid)
    app.util.request({
      'url': 'entry/wxapp/tijian.city',
      data: {
        id: id,
        hid: hid
      },
      success: function (res) {

        var city = res.data.host
        console.log(res)
        //查询下面城市
        app.util.request({
          'url': 'entry/wxapp/tijian.bumen',
          data: {
            city: city,
            id: id
          },
          success: function (res) {
            console.log(res)
            var address = res.data
            var nesARR = that.data.nesARR
            for (var i = 0; i < address.length; i++) {
              nesARR.push(address[i].list)
            }
            that.setData({
              bm: res.data,
              nesARR: nesARR[0],
              newarrs: nesARR
            })
          }
        })
      }
    })
  },
  selectCity(e) {
    console.log(e)
    var that = this
    var city = e.currentTarget.dataset.id
    var index = e.currentTarget.dataset.index
    app.util.request({
      'url': 'entry/wxapp/tijian.onebumen',
      data: {
        city: city,
      },
      success: function (res) {
        console.log(res)
        that.setData({
          nesARR: res.data,
          selectCityIndex: index
        })
      }
    })
  },
  close: function () {
    this.setData({
      showOrgList: false
    })
  },
  closeList: function () {
    this.setData({
      showOrgList: !1
    })
  },
  goNext(e) {
    console.log(e)
    var that = this
    var id = that.data.id
    var title = e.currentTarget.dataset.title
    var count = e.currentTarget.dataset.count
    var money = e.currentTarget.dataset.money
    var project = e.currentTarget.dataset.project
    var project_id = "";
    if(project.length > 0)
    {
      for(var i=0;i<project.length;i++)
      {
        project_id += project[i].id+','
      }
      project_id = project_id.substring(0,project_id.length-1)
    }
    var detail = JSON.stringify(e.currentTarget.dataset.nesarr[0])
    var bm = JSON.stringify(that.data.bm)
    var is_fenxiao = that.data.is_fenxiao
    var hid = JSON.stringify(that.data.hid)
    var openid = wx.getStorageSync('openid');
    if(openid == '')
    {
      wx.showModal({
        title: '提示',
        content:"请先登录",
        success:function(con)
        {
          if(con.confirm)
          {
            wx.navigateTo({
              url: '/hyb_yl/sgin/sgin',
            })
          }else{
            wx.switchTab({
              url: '/hyb_yl/tabBar/index/index',
            })
          }
        }
      })
    }else{
      wx.navigateTo({
        url: '/hyb_yl/userLife/pages/tijian/physical/appoint/appoint?tid=' + id + '&count=' + count + '&money=' + money + '&detail=' + encodeURIComponent(detail) + '&title=' + title + '&project=' + project_id + '&bm=' + bm + '&is_fenxiao=' + is_fenxiao + '&hid=' + hid,
      })
    }
    
  },

})